let setCookie = function (c_name, value, expiredays) {
    localStorage.setItem(c_name, JSON.stringify(value) || "");
    return;
    value = value || "";
    var exdate = new Date(Date.now() + expiredays || 0)
    document.cookie = c_name + "=" + $.encode(value) +
        ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

//取回cookie
let getCookie = function (c_name) {
    const value = localStorage.getItem(c_name);
    if (value) {
        return JSON.parse(value);
    }
    return undefined;
    if (document.cookie.length > 0) {
        var array = document.cookie.split("; ");
        for (let i = 0; i < array.length; i++) {
            const element = array[i];
            let c_start, value;
            c_start = element.indexOf(c_name + "=");
            if (c_start == 0) {
                value = element.substring((c_name + "=").length);
                return $.decode(value);
            }
        }

    }
    return ""
}
export default function (cacheKey) {
    var cache = getCookie(cacheKey) || {};
    return new Proxy(cache, {
        set: function (target, key, value) {
            Reflect.set(target, key, value)
            setCookie(cacheKey, cache)
            return true;
        },
        get: function (target, key) {
            return Reflect.get(target, key)
        }
    });
}